<template>
    <div>
        <!-- 导航栏标题 -->
        <van-nav-bar title="美食专题" left-arrow @click-left="onClickLeft" />
        <!-- 搜素 -->
        <van-search @search="onSearch" error-message show-action v-model="value" background="#fff" shape="round"
            placeholder="搜索菜品" />
        <!-- 大标题 -->
        <van-sidebar class="sidebar">
            <van-sidebar-item title="美食精选榜单" />
        </van-sidebar>
        <!-- 列表 -->
        <van-grid :gutter="6" :border="false" :column-num="3">
            <van-grid-item v-for="item in SpecialList" :key="item.id">
                <van-image :src="item.images" />
                <div class="text">
                    <p style="">{{ item.texta }}</p>
                    <span style="color: #555;">12345人参与</span>
                </div>
                <p class="card">{{ item.id }}</p>
            </van-grid-item>
        </van-grid>


    </div>
</template>

<script setup>
//导航栏点击返回
const onClickLeft = () => history.back();
import httpApi from '@/http';
import { ref, onMounted, watch } from 'vue';

const SpecialList = ref([])
const value = ref('');
console.log(value);
onMounted(() => {
    httpApi.IndexApi.querySpecialList().then(res => {
        console.log(res);
        SpecialList.value = res.data.data
    })
})

// 监听输入框值的变化
watch(value, (newValue) => {
    console.log(newValue); // 在控制台输出输入框的新值
});

//搜索
const onSearch = async (value) => {
    try {

        const res = await httpApi.IndexApi.searchSpecial(value);
        console.log(res);
        SpecialList.value = res.data.data
    } catch (error) {
        console.error(error);
    }
};
</script>

<style lang="scss" scoped>
.van-image {
    border-radius: 20px;
    overflow: hidden;
    width: 100px;
    height: 120px;
    object-fit: fill;

}

.sidebar {
    width: 200px;
}

.text {


    p {
        font-size: 12px;
        font-weight: bold;
        margin-bottom: 10px;

        display: -webkit-box;
        -webkit-line-clamp: 2;
        /* 显示两行 */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

.card {
    width: 30px;
    line-height: 35px;
    background-color: red;
    border-radius: 11px 0;
    color: #fff;
    text-align: center;
    position: absolute;
    left: 8px;
    top: 16px;
}
</style>